﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LogicUniversityBiz
{
    public class DayMatcher
    {
        private Dictionary<string, int> ToDateMatcher = new Dictionary<string, int>();
        private Dictionary<string, int> FromDateMatcher = new Dictionary<string, int>();

        private DateTime date;

        private void initializeDayMatcher()
        {

            //initializing ToDateMatcher
            ToDateMatcher.Add("Monday", 4);
            ToDateMatcher.Add("Tuesday", 5);
            ToDateMatcher.Add("Wednesday", 6);
            ToDateMatcher.Add("Thursday", 7);
            ToDateMatcher.Add("Friday", 1);
            ToDateMatcher.Add("Saturday", 2);
            ToDateMatcher.Add("Sunday", 3);

            //initializing FromDateMatcher
            FromDateMatcher.Add("Monday", 3);
            FromDateMatcher.Add("Tuesday", 4);
            FromDateMatcher.Add("Wednesday", 5);
            FromDateMatcher.Add("Thursday", 6);
            FromDateMatcher.Add("Friday", 7);
            FromDateMatcher.Add("Saturday", 1);
            FromDateMatcher.Add("Sunday", 2);
        }

        public DayMatcher()
        {
            initializeDayMatcher();
        }

        public DayMatcher(DateTime date):this()
        {
            this.date=date;
        }

        public DateTime calculateFromDate()
        {
            DateTime toDate = calculateToDate();
            int fromDay = FromDateMatcher[toDate.DayOfWeek.ToString()];
            DateTime fromDate = toDate.AddDays(-fromDay);// new DateTime(2013, 8, 20); //

            return fromDate;
        }

        public DateTime calculateToDate()
        {
            
            int toDay = ToDateMatcher[date.DayOfWeek.ToString()];
            DateTime toDate = date.AddDays(-toDay); //new DateTime(2013, 8, 26); //

            return toDate;
        }
    }
}
